package com.hsytech.dijiebao.person.fragment;

import java.util.List;

import org.json.JSONObject;

import com.hsytech.dijiebao.R;
import com.hsytech.dijiebao.bean.HomeHelpTaxi;
import com.hsytech.dijiebao.bean.HomeMyTaxi;
import com.hsytech.dijiebao.home.alldetail.MyselfTaxiDetailActivity;
import com.hsytech.dijiebao.home.alldetail.TaxiDetailActivity;
import com.hsytech.dijiebao.person.activity.MoreReleaseHelpTaxiActivity;
import com.hsytech.dijiebao.person.activity.MoreReleaseMyselfTaxiActivity;
import com.hsytech.dijiebao.utils.Constants;
import com.hsytech.dijiebao.utils.SharedPreferencesTools;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ReleaseTaxiFrament extends Fragment implements OnClickListener {

	private View root;
	private TextView city_00;
	private TextView city_tv_01, city_tv_02, city_tv_03, city_tv_06, city_tv_07, city_tv_08, city_tv_09, city_tv_04;
	private LinearLayout hotel_detil00, hotel_detil01, hotel_detil02, hotel_detil03, hotel_detil04, hotel_detil05,
			hotel_detil06, hotel_detil07, hotel_detil08, hotel_detil09;
	private TextView content00, content01, content02, content03, content04, content05, content06, content07;

	private List<HomeHelpTaxi> hh;
	private List<HomeMyTaxi> hm;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		root = inflater.inflate(R.layout.my_lease_taxi, container, false);
		initBody();
		getUI();
		getHttp();
		return root;
	}

	private void countHelpTaxi() {
		Log.d("mylog", hh.size() + "countcountcountcount");

		switch (hh.size()) {
		case 0:
			break;
		case 1:
			hotel_detil01.setVisibility(View.VISIBLE);
			// showFragment(NAVI_MY);
			break;
		case 2:
			hotel_detil01.setVisibility(View.VISIBLE);
			hotel_detil02.setVisibility(View.VISIBLE);
			// showFragment(NAVI_RELEASE);
			break;
		case 3:
			hotel_detil01.setVisibility(View.VISIBLE);
			hotel_detil02.setVisibility(View.VISIBLE);
			hotel_detil03.setVisibility(View.VISIBLE);
			break;

		case 4:
			hotel_detil01.setVisibility(View.VISIBLE);
			hotel_detil02.setVisibility(View.VISIBLE);
			hotel_detil03.setVisibility(View.VISIBLE);
			hotel_detil04.setVisibility(View.VISIBLE);
			break;
		default:
			break;
		}

	}

	private void getHttp() {
		// ����
//		RequestParams data = new RequestParams();
//		data.put("token", SharedPreferencesTools.getTOKEN(getActivity()));
//		data.put("type", 1);
//		HttpUtils.get(Constants.HTTP_MY_LIST, getActivity(), data, new JsonResponseHandler() {
//			@Override
//			public void onSuccess(JSONObject data) {
//				// JSONObject response = data.optJSONObject("result");
//
//				hm = com.alibaba.fastjson.JSONArray
//						.parseArray(data.optJSONObject("result").optJSONArray("rental").toString(), HomeMyTaxi.class);
//
//				countTaxi();
//				switch (hm.size()) {
//				case 0:
//					break;
//				case 1:
//					city_tv_06.setText(hm.get(0).getCity_name());
//					content04.setText(hm.get(0).getCat_name() + " " + hm.get(0).getStart_time() + "-"
//							+ hm.get(0).getEnd_time() + " �˳�" + hm.get(0).getNum() + "��");
//					// showFragment(NAVI_MY);
//					break;
//				case 2:
//					city_tv_06.setText(hm.get(0).getCity_name());
//					city_tv_07.setText(hm.get(1).getCity_name());
//					content04.setText(hm.get(0).getCat_name() + " " + hm.get(0).getStart_time() + "-"
//							+ hm.get(0).getEnd_time() + " �˳�" + hm.get(0).getNum() + "��");
//					content05.setText(hm.get(1).getCat_name() + " " + hm.get(1).getStart_time() + "-"
//							+ hm.get(1).getEnd_time() + " �˳�" + hm.get(1).getNum() + "��");
//					// showFragment(NAVI_RELEASE);
//					break;
//				case 3:
//					city_tv_06.setText(hm.get(0).getCity_name());
//					city_tv_07.setText(hm.get(1).getCity_name());
//					city_tv_08.setText(hm.get(2).getCity_name());
//					content04.setText(hm.get(0).getCat_name() + " " + hm.get(0).getStart_time() + "-"
//							+ hm.get(0).getEnd_time() + " �˳�" + hm.get(0).getNum() + "��");
//					content05.setText(hm.get(1).getCat_name() + " " + hm.get(1).getStart_time() + "-"
//							+ hm.get(1).getEnd_time() + " �˳�" + hm.get(1).getNum() + "��");
//					content06.setText(hm.get(2).getCat_name() + " " + hm.get(2).getStart_time() + "-"
//							+ hm.get(2).getEnd_time() + " �˳�" + hm.get(2).getNum() + "��");
//					break;
//
//				case 4:
//					city_tv_06.setText(hm.get(0).getCity_name());
//					city_tv_07.setText(hm.get(1).getCity_name());
//					city_tv_08.setText(hm.get(2).getCity_name());
//					city_tv_09.setText(hm.get(3).getCity_name());
//					content04.setText(hm.get(0).getCat_name() + " " + hm.get(0).getStart_time() + "-"
//							+ hm.get(0).getEnd_time() + " �˳�" + hm.get(0).getNum() + "��");
//					content05.setText(hm.get(1).getCat_name() + " " + hm.get(1).getStart_time() + "-"
//							+ hm.get(1).getEnd_time() + " �˳�" + hm.get(1).getNum() + "��");
//					content06.setText(hm.get(2).getCat_name() + " " + hm.get(2).getStart_time() + "-"
//							+ hm.get(2).getEnd_time() + " �˳�" + hm.get(2).getNum() + "��");
//					content07.setText(hm.get(3).getCat_name() + " " + hm.get(3).getStart_time() + "-"
//							+ hm.get(3).getEnd_time() + " �˳�" + hm.get(3).getNum() + "��");
//					break;
//				default:
//					break;
//				}
//				hh = com.alibaba.fastjson.JSONArray
//						.parseArray(data.optJSONObject("result").optJSONArray("find").toString(), HomeHelpTaxi.class);
//				countHelpTaxi();
//				// for (int i = 0; i < hm.size(); i++) {
//				// hm.get(0).getName();
//				// hm.get(hm.size() - 1).getName();
//				// Log.d("mylog", hm.get(i).getName() + "");
//				// }
//				switch (hh.size()) {
//				case 0:
//					break;
//				case 1:
//					city_tv_01.setText(hh.get(0).getCity_name());
//					content00.setText(hh.get(0).getCat_name() + " " + hh.get(0).getStart_time() + "-"
//							+ hh.get(0).getEnd_time() + " �˳�" + hh.get(0).getNum() + "��");
//					// showFragment(NAVI_MY);
//					break;
//				case 2:
//					city_tv_01.setText(hh.get(0).getCity_name());
//					city_tv_02.setText(hh.get(1).getCity_name());
//					content00.setText(hh.get(0).getCat_name() + " " + hh.get(0).getStart_time() + "-"
//							+ hh.get(0).getEnd_time() + " �˳�" + hh.get(0).getNum() + "��");
//					content01.setText(hh.get(1).getCat_name() + " " + hh.get(1).getStart_time() + "-"
//							+ hh.get(1).getEnd_time() + " �˳�" + hh.get(1).getNum() + "��");
//					// showFragment(NAVI_RELEASE);
//					break;
//				case 3:
//					city_tv_01.setText(hh.get(0).getCity_name());
//					city_tv_02.setText(hh.get(1).getCity_name());
//					city_tv_03.setText(hh.get(2).getCity_name());
//					content00.setText(hh.get(0).getCat_name() + " " + hh.get(0).getStart_time() + "-"
//							+ hh.get(0).getEnd_time() + " �˳�" + hh.get(0).getNum() + "��");
//					content01.setText(hh.get(1).getCat_name() + " " + hh.get(1).getStart_time() + "-"
//							+ hh.get(1).getEnd_time() + " �˳�" + hh.get(1).getNum() + "��");
//					content02.setText(
//							hh.get(2).getCat_name() + " " + hh.get(2).getName() + " " + hh.get(2).getStart_time() + "-"
//									+ hh.get(2).getEnd_time() + " �˳�" + hh.get(2).getNum() + "��");
//					break;
//
//				case 4:
//					city_tv_01.setText(hh.get(0).getCity_name());
//					city_tv_02.setText(hh.get(1).getCity_name());
//					city_tv_03.setText(hh.get(2).getCity_name());
//					city_tv_04.setText(hh.get(3).getCity_name());
//					content00.setText(hh.get(0).getCat_name() + " " + hh.get(0).getStart_time() + "-"
//							+ hh.get(0).getEnd_time() + " �˳�" + hh.get(0).getNum() + "��");
//					content01.setText(hh.get(1).getCat_name() + " " + hh.get(1).getStart_time() + "-"
//							+ hh.get(1).getEnd_time() + " �˳�" + hh.get(1).getNum() + "��");
//					content02.setText(hh.get(2).getCat_name() + " " + hh.get(2).getStart_time() + "-"
//							+ hh.get(2).getEnd_time() + " �˳�" + hh.get(2).getNum() + "��");
//					content03.setText(hh.get(3).getCat_name() + " " + hh.get(3).getStart_time() + "-"
//							+ hh.get(3).getEnd_time() + " �˳�" + hh.get(3).getNum() + "��");
//					break;
//				default:
//					break;
//				}
//
//			}
//		});
	}

	// for (int i = 0; i < hh.size(); i++) {
	// if (hh.get(0).getCity_name().equals("")) {
	// city_tv_01.setText("����");
	// } else {
	// city_tv_01.setText(hh.get(0).getCity_name());
	// }
	// if (hh.get(hh.size() - 3).getCity_name().equals("")) {
	// city_tv_02.setText("����");
	// } else {
	// city_tv_02.setText(hh.get(hh.size() - 3).getCity_name());
	// }
	// if (hh.get(hh.size() - 2).getCity_name().equals("")) {
	// city_tv_03.setText("����");
	// } else {
	// city_tv_03.setText(hh.get(hh.size() - 2).getCity_name());
	// }
	// if (hh.get(hh.size() - 1).getCity_name().equals("")) {
	// city_tv_04.setText("����");
	// } else {
	// city_tv_04.setText(hh.get(hh.size() - 1).getCity_name());
	// }
	//
	// }
	// FindPasswodBean sm =
	// com.alibaba.fastjson.JSONObject.parseObject(data.optJSONObject("result").toString(),
	// FindPasswodBean.class);

	// });
	// }

	private void countTaxi() {
		Log.d("mylog", hm.size() + "countcountcountcount");

		switch (hm.size()) {
		case 0:
			break;
		case 1:
			hotel_detil06.setVisibility(View.VISIBLE);
			// showFragment(NAVI_MY);
			break;
		case 2:
			hotel_detil06.setVisibility(View.VISIBLE);
			hotel_detil07.setVisibility(View.VISIBLE);
			// showFragment(NAVI_RELEASE);
			break;
		case 3:
			hotel_detil06.setVisibility(View.VISIBLE);
			hotel_detil07.setVisibility(View.VISIBLE);
			hotel_detil08.setVisibility(View.VISIBLE);
			break;

		case 4:
			hotel_detil06.setVisibility(View.VISIBLE);
			hotel_detil07.setVisibility(View.VISIBLE);
			hotel_detil08.setVisibility(View.VISIBLE);
			hotel_detil09.setVisibility(View.VISIBLE);
			break;
		default:
			break;
		}

	}

	private void getUI() {
		// �����ҳ�
		city_tv_01 = (TextView) root.findViewById(R.id.city_tv_01);
		city_tv_02 = (TextView) root.findViewById(R.id.city_tv_02);
		city_tv_03 = (TextView) root.findViewById(R.id.city_tv_03);
		city_tv_04 = (TextView) root.findViewById(R.id.city_tv_04);

		content00 = (TextView) root.findViewById(R.id.content00);
		content01 = (TextView) root.findViewById(R.id.content01);

		content02 = (TextView) root.findViewById(R.id.content02);
		content03 = (TextView) root.findViewById(R.id.content03);
		// �г�
		city_tv_06 = (TextView) root.findViewById(R.id.city_tv_06);
		city_tv_07 = (TextView) root.findViewById(R.id.city_tv_07);
		city_tv_08 = (TextView) root.findViewById(R.id.city_tv_08);
		city_tv_09 = (TextView) root.findViewById(R.id.city_tv_09);

		content04 = (TextView) root.findViewById(R.id.content04);
		content05 = (TextView) root.findViewById(R.id.content05);

		content06 = (TextView) root.findViewById(R.id.content06);
		content07 = (TextView) root.findViewById(R.id.content07);

	}

	private void initBody() {
		hotel_detil01 = (LinearLayout) root.findViewById(R.id.hotel_detil01);
		hotel_detil02 = (LinearLayout) root.findViewById(R.id.hotel_detil02);
		hotel_detil03 = (LinearLayout) root.findViewById(R.id.hotel_detil03);
		hotel_detil04 = (LinearLayout) root.findViewById(R.id.hotel_detil04);

		hotel_detil01.setTag(1);
		hotel_detil02.setTag(2);
		hotel_detil03.setTag(3);
		hotel_detil04.setTag(4);
		hotel_detil01.setOnClickListener(this);
		hotel_detil02.setOnClickListener(this);
		hotel_detil03.setOnClickListener(this);
		hotel_detil04.setOnClickListener(this);

		hotel_detil06 = (LinearLayout) root.findViewById(R.id.hotel_detil06);
		hotel_detil07 = (LinearLayout) root.findViewById(R.id.hotel_detil07);
		hotel_detil08 = (LinearLayout) root.findViewById(R.id.hotel_detil08);
		hotel_detil09 = (LinearLayout) root.findViewById(R.id.hotel_detil09);
		hotel_detil06.setOnClickListener(this);
		hotel_detil07.setOnClickListener(this);
		hotel_detil08.setOnClickListener(this);
		hotel_detil09.setOnClickListener(this);
		hotel_detil06.setTag(6);
		hotel_detil07.setTag(7);
		hotel_detil08.setTag(8);
		hotel_detil09.setTag(9);

		hotel_detil00 = (LinearLayout) root.findViewById(R.id.hotel_detil00);
		hotel_detil05 = (LinearLayout) root.findViewById(R.id.hotel_detil05);
		hotel_detil00.setOnClickListener(this);
		hotel_detil05.setOnClickListener(this);
		hotel_detil00.setTag(0);
		hotel_detil05.setTag(5);

	}

	@Override
	public void onClick(View arg0) {
		int tag = (Integer) arg0.getTag();
		switch (tag) {
		case 1:
			Intent intent = new Intent(getActivity(), TaxiDetailActivity.class);
			intent.putExtra("idTaxiHelp", hh.get(0).getId());
			intent.putExtra("collectTaxi", "1");
			startActivity(intent);
			break;
		case 2:
			Intent intent1 = new Intent(getActivity(), TaxiDetailActivity.class);
			intent1.putExtra("idTaxiHelp", hh.get(1).getId());
			intent1.putExtra("collectTaxi", "1");
			startActivity(intent1);
			break;
		case 3:
			Intent intent2 = new Intent(getActivity(), TaxiDetailActivity.class);
			intent2.putExtra("idTaxiHelp", hh.get(2).getId());
			intent2.putExtra("collectTaxi", "1");
			startActivity(intent2);
			break;
		case 4:
			Intent intent3 = new Intent(getActivity(), TaxiDetailActivity.class);
			intent3.putExtra("idTaxiHelp", hh.get(3).getId());
			intent3.putExtra("collectTaxi", "1");
			startActivity(intent3);
			break;
		case 6:
			Intent intent6 = new Intent(getActivity(), MyselfTaxiDetailActivity.class);
			intent6.putExtra("idTaxi", hm.get(0).getId());
			intent6.putExtra("collectMyTaxi", "1");
			startActivity(intent6);
			break;
		case 7:
			Intent intent7 = new Intent(getActivity(), MyselfTaxiDetailActivity.class);
			intent7.putExtra("idTaxi", hm.get(1).getId());
			intent7.putExtra("collectMyTaxi", "1");
			startActivity(intent7);
			break;
		case 8:
			Intent intent8 = new Intent(getActivity(), MyselfTaxiDetailActivity.class);
			intent8.putExtra("idTaxi", hm.get(2).getId());
			intent8.putExtra("collectMyTaxi", "1");
			startActivity(intent8);
			break;
		case 9:
			Intent intent9 = new Intent(getActivity(), MyselfTaxiDetailActivity.class);
			intent9.putExtra("idTaxi", hm.get(3).getId());
			intent9.putExtra("collectMyTaxi", "1");
			startActivity(intent9);
			break;
		case 0:
			setVisive();
			Intent intent0 = new Intent(getActivity(), MoreReleaseHelpTaxiActivity.class);
			// startActivity(intent0);
			startActivityForResult(intent0, 30000);
			break;
		case 5:
			setVisive();
			Intent intent5 = new Intent(getActivity(), MoreReleaseMyselfTaxiActivity.class);
			// startActivity(intent5);
			startActivityForResult(intent5, 40000);
			break;
		}

	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		getHttp();
	}

	private void setVisive() {
		hotel_detil01.setVisibility(View.INVISIBLE);
		hotel_detil02.setVisibility(View.INVISIBLE);
		hotel_detil03.setVisibility(View.INVISIBLE);
		hotel_detil04.setVisibility(View.INVISIBLE);
		hotel_detil06.setVisibility(View.INVISIBLE);
		hotel_detil07.setVisibility(View.INVISIBLE);
		hotel_detil08.setVisibility(View.INVISIBLE);
		hotel_detil09.setVisibility(View.INVISIBLE);
	}
}
